// 加载元素控件
var table;
layui.use(['jquery', 'element', 'layer', 'laydate', 'form', 'table'], function () {
    $ = layui.jquery, element = layui.element, layer = layui.layer, form = layui.form, table = layui.table, laydate = layui.laydate;
    //获取 选中楼宇id

    var BUILDING_ID = QueryUtils.GetQueryString("activebuildingID");
    var BUSINESS_ID = QueryUtils.GetQueryString("activebusinessID");
    var data = {};
    data.BUILDING_ID = BUILDING_ID;
    data.BUSINESS_ID = BUSINESS_ID;
    //监听主tab
    element.on('tab(expense_management)', function (data1) {
        tabselect = $(this).data("2tab");
        switch (tabselect){
            case 0:
                break;
            case 1:
                //加载进行中合同
                table.render({
                    elem: '#contract'
                    , url: '/contract/contracting'
                    , where: data
                    , cols: [[
                        {field: 'STATE', event: 'setSign', title: '状态', width: 120}
                        ,{field: 'BUILDING_NAME', event: 'setSign', title: '楼宇名称', width: 200}
                        , {field: 'ROOM_NUM', event: 'setSign', title: '项目编号', width: 120}
                        , {field: 'COMPANY', event: 'setSign', title: '承租方', width: 200}
                        , {field: 'BYNAME', event: 'setSign', title: '别名', width: 120}
                        , {field: 'ROOM_AREA', event: 'setSign', title: '面积(㎡)', width: 120}
                        , {field: 'rent', event: 'setSign', title: '租金单价', width: 120}
                        , {field: 'con_hr_date', event: 'setSign', title: '承租日', width: 120}
                        , {field: 'con_end_date', event: 'setSign', title: '结束日', width: 120}
                        , {field: 'CON_TEN_DATE', event: 'setSign', title: '计租日', width: 120}
                        , {fixed: 'right', width: 250, align: 'center', title: '操作', toolbar: '#jxzbar'}

                    ]]
                    , id: 'jxzID'
                    , page: true
                    , height: '470'
                    , limit: '10'
                });
                break;
            case 2:
                //加载待完结合同
                table.render({
                    elem: '#contractdwj'
                    , url: '/contract/contractdwj'
                    , where: data
                    , cols: [[
                        {field: 'BUILDING_NAME', event: 'setSign', title: '楼宇名称', width: 200}
                        , {field: 'ROOM_NUM', event: 'setSign', title: '项目编号', width: 120}
                        , {field: 'COMPANY', event: 'setSign', title: '承租方', width: 120}
                        , {field: 'BYNAME', event: 'setSign', title: '别名', width: 120}
                        , {field: 'ROOM_AREA', event: 'setSign', title: '面积(㎡)', width: 120}
                        , {field: 'rent', event: 'setSign', title: '租金单价', width: 120}
                        , {field: 'con_hr_date', event: 'setSign', title: '计租日', width: 120}
                        , {field: 'con_end_date', event: 'setSign', title: '结束日', width: 120}
                        , {fixed: 'right', width: 250, align: 'center', title: '操作', toolbar: '#dwjbar'}

                    ]]
                    , id: 'dwjID'
                    , page: true
                    , height: '470'
                    , limit: '10'
                });
                break;
            case 3:
                //加载已完结合同
                table.render({
                    elem: '#contractywj'
                    , url: '/contract/contractywj'
                    , where: data
                    , cols: [[
                        {field: 'BUILDING_NAME', event: 'setSign', title: '楼宇名称', width: 200}
                        , {field: 'ROOM_NUM', event: 'setSign', title: '项目编号', width: 120}
                        , {field: 'COMPANY', event: 'setSign', title: '承租方', width: 120}
                        , {field: 'BYNAME', event: 'setSign', title: '别名', width: 120}
                        , {field: 'ROOM_AREA', event: 'setSign', title: '面积(㎡)', width: 120}
                        , {field: 'rent', event: 'setSign', title: '租金单价', width: 120}
                        , {field: 'con_hr_date', event: 'setSign', title: '计租日', width: 120}
                        , {field: 'con_end_date', event: 'setSign', title: '结束日', width: 120}
                        , {fixed: 'right', width: 250, align: 'center', title: '操作', toolbar: '#ywjbar'}

                    ]]
                    , id: 'ywjID'
                    , page: true
                    , height: '470'
                    , limit: '10'
                });
                break;
            case 4:
                //加载 审批 合同
                table.render({
                    elem: '#contractshenhe'
                    , url: '/contract/contractshenpizhong'
                    , where: data
                    , cols: [[
                        {field: 'BUILDING_NAME', event: 'setSign', title: '楼宇名称', width: 200}
                        , {field: 'ROOM_NUM', event: 'setSign', title: '项目编号', width: 120}
                        , {field: 'COMPANY', event: 'setSign', title: '承租方', width: 120}
                        , {field: 'BYNAME', event: 'setSign', title: '别名', width: 120}
                        , {field: 'ROOM_AREA', event: 'setSign', title: '面积(㎡)', width: 120}
                        , {field: 'rent', event: 'setSign', title: '租金单价', width: 120}
                        , {field: 'con_hr_date', event: 'setSign', title: '计租日', width: 120}
                        , {field: 'con_end_date', event: 'setSign', title: '结束日', width: 120}
                        , {field: 'CHECK_STATE', event: 'setSign', title: '状态', width: 150,templet: '#ContractTpl1'}
                        , {fixed: 'right', width: 250, align: 'center', title: '操作', toolbar: '#shenhebar'}

                    ]]
                    , id: 'shenheID'
                    , page: true
                    , height: '470'
                    , limit: '10'
                });
                break;
            case 5:
                //加载将到期合同
                table.render({
                    elem: '#contractjdq'
                    , url: '/contract/contractjdq'
                    , where: data
                    , cols: [[
                        {field: 'BUILDING_NAME', event: 'setSign', title: '楼宇名称',width: 200}
                        , {field: 'ROOM_NUM', event: 'setSign', title: '项目编号', width: 120}
                        , {field: 'COMPANY', event: 'setSign', title: '承租方', width: 120}
                        , {field: 'BYNAME', event: 'setSign', title: '别名', width: 120}
                        , {field: 'ROOM_AREA', event: 'setSign', title: '面积(㎡)', width: 120}
                        , {field: 'rent', event: 'setSign', title: '租金单价', width: 120}
                        , {field: 'con_hr_date', event: 'setSign', title: '计租日', width: 120}
                        , {field: 'con_end_date', event: 'setSign', title: '结束日', width: 120,templet: '#contract_expires'}
                        , {fixed: 'right', width: 250, align: 'center', title: '操作', toolbar: '#daoqibar'}

                    ]]
                    , id: 'jdqID'
                    , page: true
                    , height: '470'
                    , limit: '10'
                });
                break;
        }
    });

    //初始化时间
    laydate.render({
        elem: '#START_DATE'
        , format: 'yyyy-MM-dd'
    });
    laydate.render({
        elem: '#START_DATEw'
        , format: 'yyyy-MM-dd'
    });
    laydate.render({
        elem: '#START_DATEy'
        , format: 'yyyy-MM-dd'
    });
    laydate.render({
        elem: '#END_DATE'
        , format: 'yyyy-MM-dd'
    });
    laydate.render({
        elem: '#END_DATEw'
        , format: 'yyyy-MM-dd'
    });
    laydate.render({
        elem: '#END_DATEy'
        , format: 'yyyy-MM-dd'
    });
    laydate.render({
        elem: '#CON_END_DATE'
        , format: 'yyyy-MM-dd'
    });
    //日期范围
    laydate.render({
        elem: '#TEN_END'
        ,type: 'month'
        ,range: '~'
        ,format: 'yyyy-MM'
    });
    //查询 进行中的合同
    $('.operateTable .layui-btn').on('click', function () {
        var data = {};
        data.BUILDING_NAME = $("#BUILDING_NAME").val();
        data.ROOM_NUM = $("#ROOM_NUM").val();
        data.COMPANY_NAME = $("#COMPANY_NAME").val();
        date = $("#TEN_END").val();//合同检索时间条件
        data.TEN_STA= date.substring(0, 7);
        data.TEN_END= date.substring(10, 17);
        console.log(data)
        data.BUILDING_ID = BUILDING_ID;
        data.BUSINESS_ID = BUSINESS_ID;
        table.reload('jxzID', {
            where: data
        });
    });
    //查询 待完结的合同
    $('.operateTabledwj .layui-btn').on('click', function () {
        var data = {};
        data.BUILDING_NAME = $("#BUILDING_NAMEdwj").val();
        data.ROOM_NUM = $("#ROOM_NUMdwj").val();
        data.COMPANY_NAME = $("#COMPANY_NAMEdwj").val();
        data.BUILDING_ID = BUILDING_ID;
        data.BUSINESS_ID = BUSINESS_ID;
        table.reload('dwjID', {
            where: data
        });
    });
    //查询 已完结的合同
    $('.operateTableywj .layui-btn').on('click', function () {
        var data = {};
        data.BUILDING_NAME = $("#BUILDING_NAMEywj").val();
        data.ROOM_NUM = $("#ROOM_NUMywj").val();
        data.COMPANY_NAME = $("#COMPANY_NAMEywj").val();
        data.BUILDING_ID = BUILDING_ID;
        data.BUSINESS_ID = BUSINESS_ID;
        table.reload('ywjID', {
            where: data
        });

    });
    //加载 暂存 合同
    table.render({
        elem: '#contractzancun'
        , url: '/contract/contractzancun'
        , where: data
        , cols: [[
            {field: 'BUILDING_NAME', event: 'setSign', title: '楼宇名称', width: 200}
            , {field: 'ROOM_NUM', event: 'setSign', title: '项目编号', width: 120}
            , {field: 'COMPANY', event: 'setSign', title: '承租方', width: 120}
            , {field: 'BYNAME', event: 'setSign', title: '别名', width: 120}
            , {field: 'ROOM_AREA', event: 'setSign', title: '面积(㎡)', width: 120}
            , {field: 'rent', event: 'setSign', title: '租金单价', width: 120}
            , {field: 'con_hr_date', event: 'setSign', title: '计租日', width: 120}
            , {field: 'con_end_date', event: 'setSign', title: '结束日', width: 120}
            /*, {field: 'CHECK_STATE', event: 'setSign', title: '状态', width: 120}*/
            , {fixed: 'right', width: 250, align: 'center', title: '操作', toolbar: '#zancunbar'}

        ]]
        , id: 'zancunID'
        , page: true
        , height: '470'
        , limit: '10'
    });
    //查询  审批 合同
    $('.operateTableshenhe .layui-btn').on('click', function () {
        var data = {};
        data.BUILDING_NAME = $("#BUILDING_NAMEsp").val();
        data.ROOM_NUM = $("#ROOM_NUMsp").val();
        data.COMPANY_NAME = $("#COMPANY_NAMEsp").val();
        data.BUILDING_ID = BUILDING_ID;
        data.BUSINESS_ID = BUSINESS_ID;
        table.reload('shenheID', {
            where: data
        });
    });
    //查询  审批 合同
    $('.operateTablezancun .layui-btn').on('click', function () {
        var data = {};
        data.BUILDING_NAME = $("#BUILDING_NAMEzc").val();
        data.ROOM_NUM = $("#ROOM_NUMzc").val();
        data.COMPANY_NAME = $("#COMPANY_NAMEzc").val();
        data.BUILDING_ID = BUILDING_ID;
        data.BUSINESS_ID = BUSINESS_ID;
        table.reload('zancunID', {
            where: data
        });
    });
    //查询 将到期中的合同
    $('.operateTabledaoqi .layui-btn').on('click', function () {
        var data = {};
        data.BUILDING_NAME = $("#BUILDING_NAMEdq").val();
        data.ROOM_NUM = $("#ROOM_NUMdq").val();
        data.COMPANY_NAME = $("#COMPANY_NAMEdq").val();
        data.CON_END_DATE = $("#CON_END_DATE").val();
        data.BUILDING_ID = BUILDING_ID;
        data.BUSINESS_ID = BUSINESS_ID;
        table.reload('jdqID', {
            where: data
        });
    });
    //进行中的合同 操作
    table.on('tool(jxzf)', function (obj) {
        var data = obj.data //获得当前行数据
            , layEvent = obj.event; //获得 lay-event 对应的值
        if (layEvent === 'detail') {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '查看合同',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['80%', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/contract_info.html?CONTRACT_ID=' + data.id + ''  //iframe的url
            });
        } else if (layEvent === 'yclbar') {

        } else if (layEvent === 'tuizu') {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '合同退租',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['80%', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/surrender_of_tenancy.html?CONTRACT_ID=' + data.id + ''  //iframe的url
            });
        } else if (layEvent === 'change') {
            parent.layer.open({
                type: 2,    //弹出类型
                title: '变更合同',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['1000px', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/contract_change.html?CONTRACT_ID=' + data.id + "&TYPE=change"  //iframe的url
            });
            $(this).blur(); //移除焦点，防止点击回车按钮造成多次打开
        } else if (layEvent === 'zuofei') {
            layer.confirm('确定要作废合同，同时作废所有相关账单？', {
                btn: ['确定', '取消'], //按钮
                icon: 3
            }, function(){
                $.ajax({
                    url: "/contract/zuofei",
                    data: {CONTRACT_ID: data.id},
                    dataType: "json",
                    type: "post",
                    async: false,
                    success: function (res) {
                        if (res.errcode === "0") {
                            table.reload("jxzID", {});
                            reloadshenheID();
                            layer.msg("作废提交成功", {offset: '150px'});
                            window.parent.frames[0].reloadjxzID();//刷新 进行中合同
                        } else if (res.errcode === "1") {
                            layer.msg(res.errmsg, function () {
                            });
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.error(XMLHttpRequest.status);
                        console.error(XMLHttpRequest.readyState);
                        console.error(textStatus);
                    }
                });
            }, function(){
                layer.msg("已取消", {offset: '150px'});
            });
        }
    });
    //审批中的合同 查看 修改操作
    table.on('tool(shenhef)', function (obj) {
        var data = obj.data //获得当前行数据
            , layEvent = obj.event; //获得 lay-event 对应的值
        if (layEvent === 'detail') {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '查看合同',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['80%', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/contract_info.html?CONTRACT_ID=' + data.id + ''  //iframe的url
            });
        } else if (layEvent === 'update') {
            if("退租不通过"==data.CHECK_STATE){//退租不通过的时候 弹出退租合同页
                parent.layer.open({
                    zIndex: 1000,
                    type: 2,    //弹出类型
                    title: '合同退租',   //标题
                    closeBtn: 1,    //显示关闭按钮
                    shade: [0.3],   //遮罩透明度
                    area: ['80%', '90%'],  //打开窗口的宽高
                    time: 0,    //几秒后自动关闭，默认0时不关闭
                    anim: 1,    //动画效果
                    resize: false,  //设置成不允许拉伸
                    content: '../../../webhtml/contract/surrender_of_tenancy.html?CONTRACT_ID=' + data.id + ''  //iframe的url
                });
            }else if("作废审核不通过"==data.CHECK_STATE){
                layer.confirm('确定要作废合同，同时作废所有相关账单？', {
                    btn: ['确定', '取消'], //按钮
                    icon: 3
                }, function(){
                    $.ajax({
                        url: "/contract/zuofei",
                        data: {CONTRACT_ID: data.id},
                        dataType: "json",
                        type: "post",
                        async: false,
                        success: function (res) {
                            if (res.errcode === "0") {
                                table.reload("jxzID", {});
                                reloadshenheID();
                                layer.msg("作废提交成功", {offset: '150px'});
                            } else if (res.errcode === "1") {
                                layer.msg(res.errmsg, function () {
                                });
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            console.error(XMLHttpRequest.status);
                            console.error(XMLHttpRequest.readyState);
                            console.error(textStatus);
                        }
                    });
                }, function(){
                    layer.msg("已取消", {offset: '150px'});
                });
            }else if("变更审核不通过"==data.CHECK_STATE){
                parent.layer.open({
                    type: 2,    //弹出类型
                    title: '变更合同',   //标题
                    closeBtn: 1,    //显示关闭按钮
                    shade: [0.3],   //遮罩透明度
                    area: ['1000px', '90%'],  //打开窗口的宽高
                    time: 0,    //几秒后自动关闭，默认0时不关闭
                    anim: 1,    //动画效果
                    resize: false,  //设置成不允许拉伸
                    content: '../../../webhtml/contract/contract_change.html?CONTRACT_ID=' + data.id + "&TYPE=change"  //iframe的url
                });
                $(this).blur(); //移除焦点，防止点击回车按钮造成多次打开
            }else {
                parent.layer.open({
                    type: 2,    //弹出类型
                    title: '修改合同',   //标题
                    closeBtn: 1,    //显示关闭按钮
                    shade: [0.3],   //遮罩透明度
                    area: ['1000px', '90%'],  //打开窗口的宽高
                    time: 0,    //几秒后自动关闭，默认0时不关闭
                    anim: 1,    //动画效果
                    resize: false,  //设置成不允许拉伸
                    content: '../../../webhtml/contract/contract_add.html?CONTRACT_ID=' + data.id + "&TYPE=edit"  //iframe的url
                });
                $(this).blur(); //移除焦点，防止点击回车按钮造成多次打开
            }

        }else if (layEvent === 'cancel') {
            //审批中 的合同 可以取消
            layer.confirm('确定取消审核中的合同？', {
                btn: ['确定', '取消'], //按钮
                icon: 3
            }, function(){
                $.ajax({
                    url: "/contract/cancelShenpi",
                    data: {CONTRACT_ID: data.id,CHECK_STATE: data.CHECK_STATE},
                    dataType: "json",
                    type: "post",
                    async: false,
                    success: function (res) {
                        if (res.errcode === "0") {
                            table.reload("jxzID", {});
                            reloadshenheID();
                            layer.msg("已取消", {offset: '150px'});
                        } else if (res.errcode === "1") {
                            layer.msg(res.errmsg, function () {
                            });
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.error(XMLHttpRequest.status);
                        console.error(XMLHttpRequest.readyState);
                        console.error(textStatus);
                    }
                });
            }, function(){
                // layer.msg("已取消", {offset: '150px'});
            });
        }
    });
    //待完结的合同 查看 修改操作
    table.on('tool(dwjf)', function (obj) {
        var data = obj.data //获得当前行数据
            , layEvent = obj.event; //获得 lay-event 对应的值
        if (layEvent === 'detail') {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '查看合同',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['80%', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/contract_info.html?CONTRACT_ID=' + data.id + ''  //iframe的url
            });
        } else if (layEvent === 'yclbar') {

        }
    });
    //已完结的合同 查看 修改操作
    table.on('tool(ywjf)', function (obj) {
        var data = obj.data //获得当前行数据
            , layEvent = obj.event; //获得 lay-event 对应的值
        if (layEvent === 'detail') {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '查看合同',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['80%', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/contract_info.html?CONTRACT_ID=' + data.id + ''  //iframe的url
            });
        } else if (layEvent === 'yclbar') {

        }
    });
    //暂存中的合同  操作
    table.on('tool(zancunf)', function (obj) {
        var data = obj.data //获得当前行数据
            , layEvent = obj.event; //获得 lay-event 对应的值
        if (layEvent === 'detail') {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '查看合同',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['80%', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/contract_info.html?CONTRACT_ID=' + data.id + ''  //iframe的url
            });
        } else if (layEvent === 'update') {
            parent.layer.open({
                type: 2,    //弹出类型
                title: '继续编辑合同',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['1000px', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/contract_add.html?CONTRACT_ID=' + data.id + "&TYPE=edit",  //iframe的url,
                end: function () {
                    table.reload("zancunID",{});
                }
            });
            $(this).blur(); //移除焦点，防止点击回车按钮造成多次打开
        }
        else if (layEvent === 'del') {
            layer.msg('确定删除(' + data.ROOM_NUM+ ')合同？', {
                time: 20000, //20s后自动关闭
                btn: ['确定', '取消',]
                ,yes: function(index){
                    layer.close(index); // 关闭当前提示框
                    $.ajax({
                        url: "/contract/delete",
                        data: data,
                        dataType: "json",
                        type: "post",
                        async: false,
                        success: function (res) {
                            if (res.errcode === "0") {
                                var i = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(i);  // 关闭修改房间页面
                                parent.layer.msg("删除成功", {offset: '150px'});   // 父页面弹出修改成功
                                reloadzancunID();
                            } else if (res.errcode === "1") {
                                layer.msg(res.errmsg, function () {
                                });
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            console.error(XMLHttpRequest.status);
                            console.error(XMLHttpRequest.readyState);
                            console.error(textStatus);
                        }
                    });

                }
            });

        }
    });
    //将到期的合同 操作
    table.on('tool(daoqif)', function (obj) {
        var data = obj.data //获得当前行数据
            , layEvent = obj.event; //获得 lay-event 对应的值
        if (layEvent === 'detail') {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '查看合同',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['80%', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/contract_info.html?CONTRACT_ID=' + data.id + ''  //iframe的url
            });
        } else if (layEvent === 'yclbar') {

        } else if (layEvent === 'tuizu') {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '合同退租',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['80%', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/surrender_of_tenancy.html?CONTRACT_ID=' + data.id + ''  //iframe的url
            });
        } else if (layEvent === 'change') {
            parent.layer.open({
                type: 2,    //弹出类型
                title: '变更合同',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['1000px', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/contract_change.html?CONTRACT_ID=' + data.id + "&TYPE=change"  //iframe的url
            });
            $(this).blur(); //移除焦点，防止点击回车按钮造成多次打开
        } else if (layEvent === 'zuofei') {
            layer.confirm('确定要作废合同，同时作废所有相关账单？', {
                btn: ['确定', '取消'], //按钮
                icon: 3
            }, function(){
                $.ajax({
                    url: "/contract/zuofei",
                    data: {CONTRACT_ID: data.id},
                    dataType: "json",
                    type: "post",
                    async: false,
                    success: function (res) {
                        if (res.errcode === "0") {
                            table.reload("jxzID", {});
                            reloadshenheID();
                            reloadjdqID();
                            layer.msg("作废提交成功", {offset: '150px'});
                            window.parent.frames[0].reloadjxzID();//刷新 进行中合同
                        } else if (res.errcode === "1") {
                            layer.msg(res.errmsg, function () {
                            });
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.error(XMLHttpRequest.status);
                        console.error(XMLHttpRequest.readyState);
                        console.error(textStatus);
                    }
                });
            }, function(){
                layer.msg("已取消", {offset: '150px'});
            });
        }
    });

});
//刷新进行中合同
function reloadjxzID() {
    table.reload("jxzID",{});
}
//刷新已完结合同
function reloadywjID() {
    table.reload("ywjID",{});
}
//刷新待完结合同
function reloaddwjID() {
    table.reload("dwjID",{});
}
//刷新审批中合同
function reloadshenheID() {
    table.reload("shenheID",{});
}
//刷新暂存中合同
function reloadzancunID() {
    table.reload("zancunID",{});
}
//刷新将到期合同
function reloadjdqID() {
    table.reload("jdqID",{});
}


